package com.ronsai.umtrack.api.https;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;

public class SafeHostnameVerifier implements HostnameVerifier {

    // 需要信任的服务器地址，格式：如baseurl为http://he.ronsai.com，则url填he.ronsai.com
    private String[] urls = {"url1", "url2"};

    @Override
    public boolean verify(String hostname, SSLSession sslSession) {
        //校验hostname是否正确，如果正确则建立连接
        boolean verifier = false;
        for (String host : urls) {
            if (host.equalsIgnoreCase(hostname)) {
                verifier = true;
                break;
            }
        }
        return verifier;
    }
}
